﻿#ifndef FACADE_H
#define FACADE_H

#include "t_facade.h"

#include <QKeyEvent>
#include <QMoveEvent>
#include <QContextMenuEvent>
#include <QCursor>
#include <QThread>

#include "figure.h"

namespace Ui {
class Facade;
}

class Facade : public TransFacade
{
    Q_OBJECT

public:
    explicit Facade(QWidget *parent = 0);
    ~Facade();

    void keyPressEvent(QKeyEvent *event);
    void mouseDoubleClickEvent(QMouseEvent *);
    void contextMenuEvent(QContextMenuEvent *);
    void moveEvent(QMoveEvent *);

    void startUp();

    void startReceiver();
    void endReceiver();
    void receivedMessage();

    void processCmd(const Command &);

    void setSkin();
    void setSkin_gre();
    void setSkin_blu();
    void setSkin_pik();

    void showNote();
    void showNote2();
    void invokeCalc();
    void showCmdBox();

    void ring(const QString &, const QString &);
    void pop(const QString &, const QString &);
    void say(const QString &, unsigned sec=4);

    void createMenuAll();
    void reloadMenuAll();

    void createOptionMenu();

    void createPropsMenu();
    void editPropsMenu();
    void reloadPropsMenu();

    void createCommandMenu();
    void editCommandMenu();
    void reloadCommandMenu();

    void createLocationMenu();
    void editLocationMenu();
    void reloadLocationMenu();

    void createToolMenu();
    void editToolMenu();
    void reloadToolMenu();

    void createGroupMenu();
    void editGroupMenu();
    void reloadGroupMenu();

    void createFavoriteMenu();
    void editFavoriteMenu();
    void reloadFavoriteMenu();

    void detectLocationMenu();
    void detectToolMenu();
    void detectGroupMenu();
    void detectPropsMenu();
    void detectCommandMenu();
    void detectFavoriteMenu();

private slots:
    void processGroupAction(QAction *);
    void processFavoriteAction(QAction *);
    void processToolAction(QAction *);
    void processLocationAction(QAction *);
    void processCommandAction(QAction *);
    void processPropsAction(QAction *);
    void processMenuReload(const MenuType &type);

private:
    Ui::Facade *ui;

    Sprite sp;
    MenuFlag menuFlag;
    QString word;

    Popup *popup;
    CommandBox *cbox;

    Note *note;
    Note2 *note2;

    Receiver *receiver;
    QThread recvThread;

    QMenu *menu;
    QMenu *m_user;  // Y
    QMenu *m_location;  // Y
    QMenu *m_tool; //Y
    QMenu *m_props; //Y
    QMenu *m_note;
    QMenu *m_group;  //Y
    QMenu *m_option;
    QMenu *m_menuDetect;
    QMenu *m_menuEdit;
    QMenu *m_command;
    QMenu *m_skin;
    QMenu *m_favorite;   //Y

    QAction *greSkinAction;
    QAction *bluSkinAction;
    QAction *pikSkinAction;

    //内置组件
    QAction *showCmdBoxAction;
    QAction *showNoteAction;
    QAction *showNote2Action;
    QAction *invokeCalcAction;

    QAction *editPropsMenuAction;
    QAction *editCommandMenuAction;
    QAction *editLocationMenuAction;
    QAction *editToolMenuAction;
    QAction *editGroupMenuAction;
    QAction *editFavoriteMenuAction;

    QAction *detectPropsMenuAction;
    QAction *detectUserMenuAction;
    QAction *detectLocationAction;
    QAction *detectCommandMenuAction;
    QAction *detectToolMenuAction;
    QAction *detectGroupMenuAction;
    QAction *detectFavoriteMenuAction;

    QAction *quitAction;
    QList<QAction *> propsList;

    QHash<QString,QString> commandMenuItems;
    QHash<QString,QString> toolMenuItems;
    QHash<QString,QString> groupMenuItems;
    QHash<QString,QString> locationMenuItems;
    QHash<QString,QString> favoriteMenuItems;
    QHash<QString,QString> propsMenuItems;
};

#endif // FACADE_H
